/*
 * main.c
 *
 *  Created on: 2016-10-3
 *      Author: m
 */
#include "string.h"
#include "common.h"
#include "proc.h"
#include "protect.h"
#include "global.h"
#include "kernel.h"
#include "syscall.h"
#include "sub.h"
#include "clock.h"
#include "debug.h"
#include "task_sys.h"
#include "fcntl.h"

extern void q_test_entry();
#define CNT_BASE 10

void test_a() {
    set_text_attr(TA_FOREGROUND_RED);
    printf("kernel_main\n");
    set_text_attr(TA_FOREGROUND_GREEN | TA_FOREGROUND_INTESITY);
    printf("printf test. %%s:%s, %%d:%d %%d:%d %%x:%x %%X:%X\nprintf test end\n", "hello wold", 1234, -1234, 0x12ab, 0x12ab);

    int fd = open("/blah", O_CREATE);
    printf("fd=%d\n", fd);
    close(fd);

    while(1) {
        //printf("A%d.", get_ticks());
        delay(CNT_BASE);
    }
}

void test_b() {
    q_test_entry();
    while(1) {
        //printf("B%d.", get_ticks());
        delay(CNT_BASE);
    }
}

void test_c() {
    while(1) {
        //printf("C%d.", get_ticks());
        delay(CNT_BASE);
    }
}


static char proc_stack[NR_TASKS][STACK_SIZE] = {0};
void kernel_main() {
    int i = 0;

    g_proc_ready = g_proc_table;
    init_tty(); //clean_screen inside

    for(; i < NR_TASKS; ++i) {
        g_task_table[i].stack_top = (u32)&proc_stack[i][STACK_SIZE];
        g_task_table[i].stack_size = STACK_SIZE;
        init_proc(&g_proc_table[i], &g_task_table[i]);
    }
    //proc_table[1].tty_no = 1; //test_b output to tty1
    //proc_table[2].tty_no = 2; //test_c output to tty2

    init_clock();
    restart();
    while(1){}
}



